package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.domain.Orders;
import com.itheima.dto.OrdersDto;
import com.itheima.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public R submit(@RequestBody Orders orders){
        orderService.submit(orders);
        return R.success("下单成功");
    }

    @GetMapping("/userPage")
    public R userPage(Integer page,Integer pageSize){
         Page<OrdersDto> dtoPage =  orderService.orderPage(page,pageSize);
         return R.success(dtoPage);
    }
    @GetMapping("/page")
    public R orderPage(Integer page,Integer pageSize, Long number,String beginTime,String endTime ){
      Page<OrdersDto>  dtoPage = orderService.findByPage(page,pageSize,number,beginTime,endTime);
      return R.success(dtoPage);
    }

    @PutMapping
    public R updateStatus(@RequestBody OrdersDto ordersDto){
        orderService.updateById(ordersDto);
        return R.success(ordersDto);
    }

    @PostMapping("/again")
    public R again(@RequestBody OrdersDto ordersDto){
        orderService.again(ordersDto);
        return R.success("再来一单成功");
    }
}